import java.util.Stack;

public class MinStack {

    private Stack<Integer> s ;//普通栈
    private Stack<Integer> minStack ;// 维护当前栈的最小值

    public MinStack() {
        s = new Stack<>();
        minStack = new Stack<>();
    }

    /**
     * 入栈
     * @param val
     */
    public void push(int val) {
        s.push(val);//普通栈 必须放
        if(minStack.empty()) {
            //直接也存在最小栈一份
            minStack.push(val);
        }else {
            int peekV = minStack.peek();
            if(val <= peekV) {
                minStack.push(val);
            }
        }
    }

    /**
     * 出栈
     */
    public void pop() {
        if(!s.empty()) {
            int popV = s.pop();
            int peekVMinS = minStack.peek();
            if(popV == peekVMinS) {
                minStack.pop();
            }
        }
    }
    //获取栈顶元素,但是不删除
    public int top() {
        if(!s.empty()) {
            return s.peek();
        }
        return -1;
    }
    //获取最小栈的栈顶元素
    public int getMin() {
        if(!minStack.empty()) {
            return minStack.peek();
        }
        return -1;
    }
}